package team3;

import java.util.Comparator;

/**Comparator used for comparing Moves.
 * <p>
 * This is used specifically so that the TreeMaps that the BoardState uses will
 * function even though two moves are not at the same memory address.
 * <p>
 * This defines a total ordering on all moves, such that if
 * <code>move[0]&lt;omove[0]</code> or <code>move[0]==omove[0] && move[1]&lt;omove[1]</code>
 * then <code>move&lt;omove</code>
 * <p>
 * NOTE: This is only defined for arrays of length 2; exceptions will result
 * with arrays smaller, and undesirable behavior with arrays larger then 2.
 */
public class MoveComparator implements Comparator<int[]>
{
    /** Compares two movement arrays. Each array is of length 2.
     * @return 0 if moves are equal, -1 if <code>arg0</code> is less then <code>arg1</code>, 1 otherwise
     */
	public int compare(int[] arg0, int[] arg1)
	{
		if (arg0[0] == arg1[0] && arg0[1] == arg1[1])
			return 0;
		else if (arg0[0] < arg1[0] || (arg0[0] == arg1[0] && arg0[1] < arg1[1]))
			return -1;
		return 1;
	}
}
